var t = require;
var e = module;
var o = exports;
var i, n = this && this.__extends || (i = function (t, e) {
    return (i = Object.setPrototypeOf || {
        __proto__: []
    }
        instanceof Array &&
        function (t, e) {
            t.__proto__ = e
        } ||
        function (t, e) {
            for (var o in e) Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o])
        })(t, e)
},
    function (t, e) {
        function o() {
            this.constructor = t
        }
        i(t, e),
            t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o)
    }),
    a = this && this.__decorate ||
        function (t, e, o, i) {
            var n, a = arguments.length,
                r = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
            if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, i);
            else for (var s = t.length - 1; s >= 0; s--)(n = t[s]) && (r = (a < 3 ? n(r) : a > 3 ? n(e, o, r) : n(e, o)) || r);
            return a > 3 && r && Object.defineProperty(e, o, r),
                r
        },
    r = this && this.__awaiter ||
        function (t, e, o, i) {
            return new (o || (o = Promise))(function (n, a) {
                function r(t) {
                    try {
                        l(i.next(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function s(t) {
                    try {
                        l(i.
                            throw(t))
                    } catch (e) {
                        a(e)
                    }
                }
                function l(t) {
                    var e;
                    t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
                        t(e)
                    })).then(r, s)
                }
                l((i = i.apply(t, e || [])).next())
            })
        },
    s = this && this.__generator ||
        function (t, e) {
            var o, i, n, a, r = {
                label: 0,
                sent: function () {
                    if (1 & n[0]) throw n[1];
                    return n[1]
                },
                trys: [],
                ops: []
            };
            return a = {
                next: s(0),
                throw: s(1),
                return: s(2)
            },
                "function" == typeof Symbol && (a[Symbol.iterator] = function () {
                    return this
                }),
                a;
            function s(t) {
                return function (e) {
                    return l([t, e])
                }
            }
            function l(a) {
                if (o) throw new TypeError("Generator is already executing.");
                for (; r;) try {
                    if (o = 1, i && (n = 2 & a[0] ? i.
                        return : a[0] ? i.
                            throw || ((n = i.
                                return) && n.call(i), 0) : i.next) && !(n = n.call(i, a[1])).done) return n;
                    switch (i = 0, n && (a = [2 & a[0], n.value]), a[0]) {
                        case 0:
                        case 1:
                            n = a;
                            break;
                        case 4:
                            return r.label++,
                            {
                                value: a[1],
                                done: !1
                            };
                        case 5:
                            r.label++,
                                i = a[1],
                                a = [0];
                            continue;
                        case 7:
                            a = r.ops.pop(),
                                r.trys.pop();
                            continue;
                        default: if (!(n = (n = r.trys).length > 0 && n[n.length - 1]) && (6 === a[0] || 2 === a[0])) {
                            r = 0;
                            continue
                        }
                            if (3 === a[0] && (!n || a[1] > n[0] && a[1] < n[3])) {
                                r.label = a[1];
                                break
                            }
                            if (6 === a[0] && r.label < n[1]) {
                                r.label = n[1],
                                    n = a;
                                break
                            }
                            if (n && r.label < n[2]) {
                                r.label = n[2],
                                    r.ops.push(a);
                                break
                            }
                            n[2] && r.ops.pop(),
                                r.trys.pop();
                            continue;
                    }
                    a = e.call(t, r)
                } catch (s) {
                    a = [6, s],
                        i = 0
                } finally {
                        o = n = 0
                    }
                if (5 & a[0]) throw a[1];
                return {
                    value: a[0] ? a[1] : void 0,
                    done: !0
                }
            }
        };
Object.defineProperty(o, "__esModule", {
    value: !0
});
var l = t("CarConstant"),
    c = t("GlobalUserData"),
    d = t("GameConstant"),
    h = t("GameLogic"),
    p = t("AssemblyItem"),
    u = t("HallConstant"),
    f = t("BroadCastMessage"),
    m = t("Common"),
    _ = t("Util"),
    y = t("ChampionManager"),
    g = t("SuperChariot"),
    v = t("GameSpeedClickView"),
    C = cc._decorator,
    b = C.ccclass,
    w = C.property,
    S = function (t) {
        function e() {
            var e = null !== t && t.apply(this, arguments) || this;
            return e.pfb_assembly = null,
                e.pfb_speedClick = null,
                e.lab_leftName = null,
                e.node_leftHead = null,
                e.node_leftCars = new Array(3),
                e.lab_rightName = null,
                e.node_rightHead = null,
                e.node_RightCars = new Array(3),
                e.lab_countDown = null,
                e.node_countDown = null,
                e.spr_head = null,
                e.spr__enemyhead = null,
                e.label_trophy = null,
                e.label_etrophy = null,
                e._gameControl = null,
                e._gameLogic = null,
                e.rEquipBodyData = null,
                e.rEquipWheelData = null,
                e.rEquipWeaponData = null,
                e.rEquipToolsData = null,
                e.strRightName = null,
                e.spriteRightHead = null,
                e.rNameList = [],
                e.rHeadSpriteList = [],
                e.rShowIndex = 0,
                e.playCarAnimTimes = 0,
                e.nTotalTime = 10,
                e.leftCarCount = 0,
                e.rightCarCount = 0,
                e
        }
        return n(e, t),
            e.prototype.onLoad = function () {
                this._gameLogic = new h.GameLogic,
                    this.node_countDown.active = !1
            },
            e.prototype.onEnable = function () {
                c.default.isMatchView = !0
            },
            e.prototype.onDisable = function () {
                c.default.isMatchView = !1
            },
            e.prototype.start = function () {
                var t = this;
                this.scheduleOnce(function () {
                    y.default.Ins.setGradeWithFrame(t.spr_head),
                        y.default.Ins.setGradeWithFrame(t.spr__enemyhead),
                        t.label_trophy.string = c.default.nTrophy.toString()
                },
                    .2),
                    this.initRightInfo(),
                    this.createLeftCars(),
                    _.Util.showBanner()
            },
            e.prototype.initRightInfo = function () {
                return r(this, void 0, void 0,
                    function () {
                        var t, e;
                        return s(this,
                            function () {
                                return t = this,
                                    _.Util.showBanner(),
                                    console.log("准备加载"),
                                    cc.loader.loadRes("database/user_name", cc.JsonAsset,
                                        function (e, o) {
                                            if (e) cc.log(e);
                                            else for (var i = o.json,
                                                n = _.Util.GetRandomNumberArray(0, i.length, 10, 1), a = 0; a < n.length; a++) t.rNameList.push(i[n[a]])
                                        }),
                                    e = [],
                                    cc.loader.loadRes("database/user_head", cc.JsonAsset,
                                        function (o, i) {
                                            if (o) cc.log(o);
                                            else {
                                                for (var n = i.json,
                                                    a = _.Util.GetRandomNumberArray(0, n.length, 10, 1), r = 0; r < a.length; r++) e.push(n[a[r]]);
                                                t.loadHeadSprite(e)
                                            }
                                        }),
                                    [2]
                            })
                    })
            },
            e.prototype.loadHeadSprite = function (t) {
                console.log("加载头像")
                var e = this;
                cc.assetManager.loadBundle("Role",
                    function (o, i) {
                        if (o) return cc.error(o);
                        cc.log("load resources subpackage (Role) successfully.");
                        for (var n = 0; n < t.length; n++) i.load(t[n], cc.SpriteFrame,
                            function (t, o) {
                                e.rHeadSpriteList.push(o)
                            });
                        e.onShowRight()
                    })
            },
            e.prototype.onShowRight = function () {
                var t = this;
                if (this.showRightInfo(this.rShowIndex), this.rShowIndex++, this.rShowIndex >= 10) return this.strRightName = this.rNameList[this.rShowIndex - 1],
                    this.spriteRightHead = this.rHeadSpriteList[this.rShowIndex - 1],
                    void this.playAniShow();
                this.scheduleOnce(function () {
                    t.onShowRight()
                },
                    .2)
            },
            e.prototype.showRightInfo = function (t) {
                this.lab_rightName.string = this.rNameList[t],
                    this.node_rightHead.spriteFrame = this.rHeadSpriteList[t],
                    this.label_etrophy.string = _.Util.getRandomInt(c.default.nTrophy - 10 < 0 ? 0 : c.default.nTrophy - 10, c.default.nTrophy + 10).toString()
            },
            e.prototype.playAniShow = function () {
                var t = this;
                console.log("播放出场动画");
                var e = 3.25;
                this._gameControl.playEngineAudio(),
                    c.default.enemyTrophy = y.default.Ins.getETrophy(),
                    y.default.Ins.setGradeWithFrame(this.spr__enemyhead, c.default.enemyTrophy),
                    this.label_etrophy.string = c.default.enemyTrophy.toString();
                var o = this.leftCarCount > this.rightCarCount ? this.leftCarCount : this.rightCarCount,
                    i = this.node.getComponent(cc.Animation);
                switch (o) {
                    case 1:
                        i.play("ani_match_car1"),
                            e = 1;
                        break;
                    case 2:
                        i.play("ani_match_car2"),
                            e = 2;
                        break;
                    default: i.play("ani_matchroom"),
                        e = 3.25;
                }
                this.scheduleOnce(function () {
                    _.Util.is_wx() && (_.Util.hideBanner(), _.Util.showBanner())
                },
                    .1),
                    this.scheduleOnce(function () {
                        _.Util.is_wx() && (_.Util.hideBanner(), _.Util.showBanner())
                    },
                        1),
                    this.scheduleOnce(function () {
                        _.Util.hideBanner(),
                            c.default.isRefreshMatchBanner && (_.Util.refreshBanner(!1), _.Util.hideBanner()),
                            _.Util.is_OPPO && _.Util.hideNativeBanner(),
                            t.node_countDown.active = !0,
                            t.onCountDown()
                    },
                        e)
            },
            e.prototype.initView = function (t) {
                this._gameControl = t,
                    this.initRightData()
            },
            e.prototype.initRightData = function () {
                var t;
                t = c.default.nTotalGame < 4 ? this._gameLogic.getGuide1CarData(c.default.nEquipMax) : this._gameLogic.getRightCarData(c.default.nEquipMax, c.default.nGameGrade),
                    this.rEquipBodyData = t.body,
                    this.rEquipWheelData = t.wheel,
                    this.rEquipWeaponData = t.weapon,
                    this.rEquipToolsData = t.tools,
                    this.createRightCars()
            },
            e.prototype.onBtnStartGame = function () {
                this.playAudio(d.Game_Audio_ID.btn_click),
                    this.unscheduleAllCallbacks(),
                    m.default.getIns().logEvent(m.LogEventType.MatchStartBtn, c.default._strOldUser + "" + c.default.nTotalGame, 2),
                    c.default.nGuideStep == u.Guide_Step.trySuperCar || c.default.nGuideStep > u.Guide_Step.trySuperCar && _.Util.probability(c.default.superCarPro) ? this.superChariot(0) : this.superCarBackCall()
            },
            e.prototype.superChariot = function (t) {
                var e = this;
                cc.resources.load("prefab/superChariot", cc.Prefab,
                    function (o, i) {
                        var n = cc.instantiate(i);
                        n.getComponent(g.default).init(t, e.superCarBackCall.bind(e)),
                            e.node.addChild(n, 9999)
                    })
            },
            e.prototype.superCarBackCall = function () {
                this._gameControl.initRightData(this.rEquipBodyData, this.rEquipWheelData, this.rEquipWeaponData, this.rEquipToolsData),
                    this._gameControl.setRightInfo(this.strRightName, this.spriteRightHead),
                    this._gameControl.onBtnGameStart(),
                    this.node.active = !1,
                    this.destroy()
            },
            e.prototype.onCountDown = function () {
                var t = this;
                _.Util.is_tt() && _.Util.hideBanner();
                var e = c.default.nTotalGame % 6;
                c.default.bAuditMode || !c.default.nativeMatchBannerList[e] || _.Util.is_VIVO() && _.Util.showInterstitialAd();
                var o = c.default.nTotalGame % c.default.matchViewInsertAdList.length;
                _.Util.is_tt() && !c.default.bAuditMode && c.default.matchViewInsertAdList[o] && _.Util.showInterstitialAd(),
                    this.schedule(function () {
                        t.nTotalTime <= 0 && t.onBtnStartGame(),
                            t.nTotalTime--,
                            t.lab_countDown.string = t.nTotalTime.toString()
                    },
                        1)
            },
            e.prototype.onCreateSpeed = function () {
                var t = this,
                    e = cc.instantiate(this.pfb_speedClick);
                this.node.addChild(e),
                    e.getComponent(v.default).initView(function () {
                        t._gameControl.initRightData(t.rEquipBodyData, t.rEquipWheelData, t.rEquipWeaponData, t.rEquipToolsData),
                            t._gameControl.setRightInfo(t.strRightName, t.spriteRightHead),
                            t._gameControl.onBtnGameStart(),
                            t.unscheduleAllCallbacks(),
                            t.node.active = !1,
                            t.destroy()
                    })
            },
            e.prototype.createLeftCars = function () {
                for (var t = 0; t < c.default.nEquipMax; t++) {
                    var e = _.Util.getBodyData(c.default.curEquipBody[t]);
                    if (e) {
                        this.leftCarCount++;
                        for (var o = [], i = 0; i < c.default.curEquipWheel.length; i++) c.default.curEquipWheel[i] ? o.push(_.Util.getWheelData(c.default.curEquipWheel[t][i])) : o.push(null);
                        var n = [];
                        for (i = 0; i < c.default.curEquipWeapon.length; i++) c.default.curEquipWeapon[i] ? n.push(_.Util.getWeaponData(c.default.curEquipWeapon[t][i])) : n.push(null);
                        var a = [];
                        for (i = 0; i < c.default.curEquipTools.length; i++) c.default.curEquipTools[i] ? a.push(_.Util.getToolsData(c.default.curEquipTools[t][i])) : a.push(null);
                        this.createCar(!0, t, this.node_leftCars[t], e, o, n, a)
                    }
                }
            },
            e.prototype.createRightCars = function () {
                for (var t = 0; t < this.node_RightCars.length; t++) {
                    var e = this.rEquipBodyData[t];
                    if (e) {
                        this.rightCarCount++;
                        var o = this.rEquipWheelData[t],
                            i = this.rEquipWeaponData[t],
                            n = this.rEquipToolsData[t];
                        this.createCar(!1, t, this.node_RightCars[t], e, o, i, n)
                    }
                }
            },
            e.prototype.createCar = function (t, e, o, i, n, a, r) {
                var s = l.GetCarBodyData(i.id);
                this.createCarBody(t, e, o, i, n),
                    this.createCarWheel(t, e, o, n, s.wheelPos),
                    this.createCarWeapon(t, e, o, a, s.weaponPos),
                    this.createCarTools(t, e, o, r, s.toolsPos)
            },
            e.prototype.createCarBody = function (t, e, o, i, n) {
                var a = cc.instantiate(this.pfb_assembly);
                o.addChild(a);
                var r = a.getComponent(p.AssemblyItem),
                    s = !!n[0],
                    l = !!n[0];
                r.updateItem(null, t, 0, i, !1, p.Assembly_Type.GameMatch, s, l)
            },
            e.prototype.createCarWheel = function (t, e, o, i, n) {
                for (var a = 0; a < i.length; a++) if (i[a]) {
                    var r = cc.instantiate(this.pfb_assembly);
                    o.addChild(r, 20),
                        r.position = n[a],
                        r.getComponent(p.AssemblyItem).updateItem(null, t, 0, i[a], !1, p.Assembly_Type.GameMatch)
                }
            },
            e.prototype.createCarWeapon = function (t, e, o, i, n) {
                for (var a = 0; a < i.length; a++) if (i[a]) {
                    var r = cc.instantiate(this.pfb_assembly);
                    o.addChild(r, 30),
                        r.position = n[a],
                        r.getComponent(p.AssemblyItem).updateItem(null, t, 0, i[a], !1, p.Assembly_Type.GameMatch)
                }
            },
            e.prototype.createCarTools = function (t, e, o, i, n) {
                for (var a = 0; a < i.length; a++) if (i[a]) {
                    var r = cc.instantiate(this.pfb_assembly);
                    o.addChild(r, 40),
                        r.position = n[a],
                        r.getComponent(p.AssemblyItem).updateItem(null, t, 0, i[a], !1, p.Assembly_Type.GameMatch)
                }
            },
            e.prototype.playAudio = function (t) {
                this._gameControl ? this._gameControl.playAudio(t) : f.default.getInstance().SendMessage(d.Game_Broadcast_Func.Audio, t)
            },
            a([w(cc.Prefab)], e.prototype, "pfb_assembly", void 0),
            a([w(cc.Prefab)], e.prototype, "pfb_speedClick", void 0),
            a([w(cc.Label)], e.prototype, "lab_leftName", void 0),
            a([w(cc.Sprite)], e.prototype, "node_leftHead", void 0),
            a([w(cc.Node)], e.prototype, "node_leftCars", void 0),
            a([w(cc.Label)], e.prototype, "lab_rightName", void 0),
            a([w(cc.Sprite)], e.prototype, "node_rightHead", void 0),
            a([w(cc.Node)], e.prototype, "node_RightCars", void 0),
            a([w(cc.Label)], e.prototype, "lab_countDown", void 0),
            a([w(cc.Node)], e.prototype, "node_countDown", void 0),
            a([w(cc.Sprite)], e.prototype, "spr_head", void 0),
            a([w(cc.Sprite)], e.prototype, "spr__enemyhead", void 0),
            a([w(cc.Label)], e.prototype, "label_trophy", void 0),
            a([w(cc.Label)], e.prototype, "label_etrophy", void 0),
            a([b], e)
    }(cc.Component);
o.default = S